﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SingletonPatternExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var state = ApplicationState.GetState();
            state.LoginId = "kanasz";
            state.MaxSize = 1024;

            var state2 = ApplicationState.GetState();
            Console.WriteLine(state2.LoginId);
            Console.WriteLine(state2.MaxSize);
            Console.WriteLine(state == state2);
            Console.Read();
        }
    }

    public sealed class ApplicationState
    {
        private static volatile ApplicationState _instance;
        private static object _lockThis = new object();

        private ApplicationState() { }

        public static ApplicationState GetState()
        {
            if (_instance == null)
            {
                lock (_lockThis)
                {
                    if (_instance == null) _instance = new ApplicationState();
                }
            }
            return _instance;
        }

        // State Information
        public string LoginId { get; set; }
        public int MaxSize { get; set; }
    }
}
